import os
import sys
import logging
from concurrent_log_handler import ConcurrentRotatingFileHandler

def logger_pilot(name=__name__,log_file=None,log_format='%(asctime)s - %(levelname)s - %(message)s', log_level=logging.INFO):
    '''创建日志记录器'''
    logger = logging.getLogger(name)
    logger.setLevel(log_level)
    if log_file is not None:
        # 创建并设置ConcurrentRotatingFileHandler
        rotateHandler = ConcurrentRotatingFileHandler(log_file, 'a', 1024*1024, 5)
        rotateHandler.setFormatter(logging.Formatter(log_format))
        logger.addHandler(rotateHandler)
    # 创建控制台处理器，并设置日志级别和格式
    consoleHandler = logging.StreamHandler()
    consoleHandler.setFormatter(logging.Formatter(log_format))
    consoleHandler.setLevel(logging.INFO)
    logger.addHandler(consoleHandler)
    return logger

if __name__ == "__main__":
    logger = logger_pilot()
    logger.debug('====debug====')
    logger.info('====info====')
    logger.warning('====warning====')
    logger.error('====error====')